import Vue from 'vue'
import Router from 'vue-router'
// 导入路由
import routes from './router'

Vue.use(Router)

// 初始化路由数组
let clearRoutes = []
console.log('routes : ', routes)
for (let i = 0; i < routes.length; i++) {
  let item = routes[i]
  // 如果是组件
  if (item.component) {
    clearRoutes.push(item)
  }
  let childList = item.children
  // 如果还有子页面集合
  if (!childList) {
    continue
  }

  for (let j = 0; j < childList.length; j++) {
    let childItem = childList[j]
    childItem.path = item.path + childItem.path
    clearRoutes.push(childItem)
  }
  console.log('clearRoutes : ', clearRoutes)
}

export default new Router({
  mode: 'history',
  routes: clearRoutes
})
